package com.lgh.springframework.context.support;

import com.lgh.springframework.beans.BeansException;
import com.lgh.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.lgh.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname AbstractRefreshableApplicationContext
 * @description
 * @date 2023/02/25 14:52
 * <p>
 * ******************************************************
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeansException {
        // 创建bean工厂
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        // 加载bean定义
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
